package com.poisonh.unifiedauth.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间工具类
 * Created by PoisonH on 2016/7/26.
 */
public class TimeUtils
{
    /**
     * 获取当前时间
     *
     * @return
     */
    public static String getNowTime()
    {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return df.format(new Date());
    }

    /**
     * 判断当前时间是否大于30天
     *
     * @param strOldTime
     * @return
     */
    public static boolean checkDate(String strOldTime)
    {
        try
        {
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date oldTime = df.parse(strOldTime);
            Date nowTime = df.parse(getNowTime());
            long value = nowTime.getTime() - oldTime.getTime();
            //long days = value / (1000 * 60 * 60 * 24);
            long days = value / (1000 * 60 * 60 * 24);
            return days >= 30;
        } catch (ParseException e)
        {
            e.printStackTrace();
        }
        return false;
    }
}
